<?php
#============================
#	Filename: datalist.qgmod.php
#	Note	: 数据调用列表
#	Version : 2.0
#	Author  : ovsexia
#	Update  : 2018-06-02
#============================
global $FS,$DB,$STR,$PA,$prefix,$bi;

foreach($datakey AS $key=>$value)
{
	$data[$key] = $STR->safe($value);
}

//读取主题列表
if($data["type"]=="msg")
{
	//排序
	$data["orderby"] = $data["orderby"] ? $data["orderby"] : "m.allsortid asc,m.id desc";
	//读取数量
	$data["limit"] = $data["limit"] ? $data["limit"] : 10;
	//标题截取
	$data["cut_subject"] = $data["cut_subject"] ? $data["cut_subject"] : 14;
	//内容截取
	$data["cut_content"] = $data["cut_content"] ? $data["cut_content"] : 100;
	//缓存文件
	$md5 = md5(TemplateID."_".$data);
	$cache_file = "data/cache/".$data["type"]."list_".$md5.".php";
	#[判断缓存文件的存储状态]
	$check_status = false;
	if($iscache)
	{
		$check_status = CheckCache($cache_file);
	}
	if($check_status)
	{
		include_once($cache_file);
		$datalist = $datalist_cache;
		return $datalist;
		exit;
	}

	$sql = "SELECT c.catename,c.catename_en,c.catename_ft,m.* FROM ".$prefix."category AS c,".$prefix."msg AS m WHERE (c.id='".$data["cateid"]."' OR c.rootid='".$data["cateid"]."' OR c.parentid='".$data["cateid"]."') AND m.ifcheck='1' AND m.additonid='0' AND m.cateid=c.id";
	$sql .= " ORDER BY ".$data["orderby"];
	$sql .= " LIMIT 0,".$data["limit"];
	$rslist = $DB->qgGetAll($sql);
	if($rslist)
	{
		foreach($rslist AS $key=>$value)
		{
			//获取图片
			$value = $PA->add_thumbarr($value);
			//获取内容
			$rs = $DB->qgGetOne("SELECT * FROM ".$prefix."msg_content WHERE id='".$value["id"]."'");
			$value["content"] = $rs["content"];
			$value["content_en"] = $rs["content_en"];
			$value["content_ft"] = $rs["content_ft"];
			$rslist[$key] = $value;
		}
		//获取系统组自定义图片尺寸
		$sysimg = $PA->sysize($data["cateid"]);
		$swidth = $sysimg["width"];
		$sheight = $sysimg["height"];
		$rslist = $PA->msgcontent($value["id"],$rslist,$data["cut_subject"],$data["cut_content"],$swidth,$sheight);
		$datalist = $rslist;
		//写入缓存文件
		$FS->qgWrite($datalist,$cache_file,"datalist_cache");
	}
}
//读取分类列表
elseif($data["type"]=="cate")
{
	//读取数量
	$data["limit"] = $data["limit"] ? $data["limit"] : 100;
	$sql = "SELECT c.*,u.folder,u.thumbfile,u.markfile,u.filename FROM ".$prefix."category AS c LEFT JOIN ".$prefix."upfiles AS u ON c.thumb=u.id WHERE c.parentid='".$data["cateid"]."' AND c.status='1' ORDER BY c.taxis ASC,c.id DESC";
	$sql .= " LIMIT 0,".$data["limit"];
	$rslist = $DB->qgGetAll($sql);
	if($rslist)
	{
		foreach($rslist AS $key=>$value)
		{
			//获取图片
			$value = $PA->add_thumbarr($value);
			$rslist[$key] = $value;
		}
		$datalist = $rslist;
	}
}
?>